import React,{useState,useMemo} from 'react';

/* 
  useMemo的使用
*/
const App = () => {
  let [age,setAge] = useState(2);
  let [num,setNum] = useState(3);
  // let doubleNum = function(){
  //   console.log("double num");
  //   return num*2;
  // }
  // let doubleNum = useMemo(() => {
  //   console.log("doubleNum");
  //   return num*2;
  // }, [age])
  let doubleNum = useMemo(() => {
    console.log("doubleNum");
    return num*2;// 值，组件和函数等等
  }, [num])
  return (
    <div>
      <h1>年龄:{age}</h1>
      <h1>num:{doubleNum}</h1>
      <button onClick={()=>{
        setAge(age+1);
      }}>age+1</button>
    </div>
  );
}

export default App;
